home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / FROMUTS / UNIXLIB37B / src / unix / c / time < prev    next >
Text File  |  1991-10-06  |  919b  |  59 lines

  1. static char sccs_id[] = "@(#) time.c 1.0 "__DATE__" HJR";
  2.  
  3. /* time.c (c) Copyright 1990 H.Rogers */
  4.  
  5. #include <time.h>
  6. #include <errno.h>
  7.  
  8. #include "sys/os.h"
  9. #include "sys/syslib.h"
  10.  
  11. clock_t clock(void)
  12. {
  13. unsigned int b[2];
  14. unsigned int t1,t2;
  15. os_error *e;
  16.  
  17. *((char *)b) = 3;
  18. if (e = os_word(0x0e,b))
  19.   {
  20.   __seterr(e);
  21.   return(-1);
  22.   }
  23.  
  24. t1 = (b[0]);
  25. t2 = (b[1] & 0xff);
  26.  
  27. if (t2 - __time[1]) { errno = ERANGE; return((clock_t)-1); }
  28.  
  29. return(t1 - __time[0]);
  30. }
  31.  
  32. time_t time(time_t *t)
  33. {
  34. unsigned int b[2];
  35. unsigned int t1,t2,tc;
  36. os_error *e;
  37.  
  38. *((char *)b) = 3;
  39. if (e = os_word(0x0e,b))
  40.   {
  41.   __seterr(e);
  42.   return(-1);
  43.   }
  44.  
  45. t1 = (b[0]);
  46. t2 = (b[1] & 0xff);
  47.  
  48. tc = 0x6e996a00U;
  49. if (t1 < tc) t2--; t1 -= tc;
  50. t2 -= 0x33;            /* 00:00:00 Jan. 1 1970 = 0x336e996a00 */
  51.  
  52. t1 = (t1 / 100) + (t2 * 42949673U);    /* 0x100000000 / 100 = 42949672.96 */
  53. t1 -= (t2 / 25);            /* compensate for .04 error */
  54.  
  55. if (t) *t = t1;
  56.  
  57. return(t1);
  58. }
  59.